package com.mengdie.shuidi;

import android.content.Context;
import android.telephony.TelephonyManager;

import com.lzy.okgo.model.HttpHeaders;
import com.mengdie.shuidi.manager.MDAccountMgr;
import com.mengdie.shuidi.manager.MDUserMgr;
import com.mengdie.shuidi.utils.StatisticsUtil;
import com.mengdie.shuidi.utils.common.AppUtils;
import com.mengdie.shuidi.utils.common.MD5Util;

/**
 * Created by apple on 16/12/21.
 */

public class OkHeader {


    //获取未登陆的公共头
    public static HttpHeaders getCommonHead(Context context) {

        //获取app 的版本号
        String appVersion = String.valueOf(AppUtils.getAppInfo(context).getVersionCode());

        //获取手机的id
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String IMEIs = new StatisticsUtil(context).getDeviceUuid().toString();

        //获取当前时间戳
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);

        String sign = "zm-auth-name=" +
                "zmdl&zm-language=cn&zm-oem=shuididaili&zm-channel="+AppContext.getInstance().getChannelName() +
                "&zm-platform=" + "android" + "&zm-timestamp=" +
                timestamp + "&zm-union-id=" + IMEIs + "&zm-version=" + appVersion +
                "PqTgfCM00i73brLBh9f7";

        //MD5签名
        String s = MD5Util.md5(sign);

        //公共请求头
        HttpHeaders headers = new HttpHeaders();
        headers.put("zm-auth-name", "zmdl");
        headers.put("zm-platform", "android");
        headers.put("zm-version", appVersion);
        headers.put("zm-union-id", IMEIs);
        headers.put("zm-oem", "shuididaili");
        headers.put("zm-channel", AppContext.getInstance().getChannelName());

        headers.put("zm-session-id", "");
        headers.put("zm-uid", "");
        headers.put("zm-username", "");
        headers.put("zm-timestamp", timestamp);
        headers.put("zm-language", "cn");
        headers.put("zm-sign", s);

        return headers;

    }

    //获取登陆的公共头
    public static HttpHeaders getCommonHeadToken(Context context) {
        String sessionId = MDAccountMgr.getInstance().getSessionId();
        String useName = MDUserMgr.getInstance().getUsername();
        String id = String.valueOf(MDUserMgr.getInstance().getId());

        //获取app 的版本号
        String appVersion = String.valueOf(AppUtils.getAppInfo(context).getVersionCode());

        //获取手机的id
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String IMEIs = new StatisticsUtil(context).getDeviceUuid().toString();

        //获取当前时间戳
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);

        String sign = "zm-auth-name=" +
                "zmdl&zm-language=cn&zm-oem=shuididaili&zm-channel="+AppContext.getInstance().getChannelName() +
                "&zm-platform=" + "android&zm-session-id=" + sessionId + "&zm-timestamp=" +
                timestamp + "&zm-uid=" + id + "&zm-union-id=" + IMEIs + "&zm-username=" + useName + "&zm-version=" + appVersion + "PqTgfCM00i73brLBh9f7";

        //MD5签名
        String s = MD5Util.md5(sign);

        //公共请求头
        HttpHeaders headers = new HttpHeaders();
        headers.put("zm-auth-name", "zmdl");
        headers.put("zm-platform", "android");
        headers.put("zm-version", appVersion);
        headers.put("zm-union-id", IMEIs);
        headers.put("zm-oem", "shuididaili");
        headers.put("zm-channel", AppContext.getInstance().getChannelName());

        headers.put("zm-session-id", sessionId);
        headers.put("zm-uid", id);
        headers.put("zm-username", useName);
        headers.put("zm-timestamp", timestamp);
        headers.put("zm-language", "cn");
        headers.put("zm-sign", s);

        return headers;

    }


}
